package com.rjpacket.supernews.app.tasks;

import android.os.AsyncTask;
import com.rjpacket.supernews.app.Constants;
import com.rjpacket.supernews.app.utils.HttpTool;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by aaa on 15-3-10.
 */
public class RecommendNewsDetailTask extends AsyncTask<String, Integer, String> {
    private DetailTaskCallOnBack back;

    private String position;

    public RecommendNewsDetailTask(DetailTaskCallOnBack back) {
        this.back = back;
    }

    @Override
    protected String doInBackground(String... params) {
        String ret = null;

        if (params != null && params.length > 2) {
            String nid = params[0];
            String db = params[1];
            String uid = params[2];
            if (params.length > 3) {
                position = params[3];
            }

            String url = Constants.APP_NEWS_API + "newsContent.m?vcode=16299&udid=073CC368CD437982D321EE88ED3EB3AF&terminal=android&cpid=bnf1377_10890_001&uid=" + uid + "&client=newsapp&db_source=" + db + "&nid=" + nid;

            byte[] bytes = HttpTool.get(url);

            if (bytes != null) {
                String str = new String(bytes);

                try {
                    ret = str;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        return ret;
    }

    @Override
    protected void onPostExecute(String jsonObject) {
        if (jsonObject != null) {
            back.callBack(jsonObject, position);
        } else {
            back.callBack(null, null);
        }
    }


}
